package com.study.freemarker.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import com.study.freemarker.beans.User;

import cn.hutool.core.util.ObjectUtil;

@Controller
public class IndexController {

	@GetMapping(value = {"", "/"})
	public ModelAndView index(HttpSession session) {
		ModelAndView mv = new ModelAndView();

		User user = (User) session.getAttribute("user");
		if (ObjectUtil.isNull(user)) {
			mv.setViewName("redirect:/user/login");
		} else {
			mv.setViewName("index");
			mv.addObject(user);
		}

		return mv;
	}
}
